package dli_and_obs

import java.io.FileInputStream
import java.util.Properties

/**
  * @Description 查询队列中在跑任务数量
  * @Author liutaowei
  * @Date 2019-5-22 16:15
  */
object job_number {
  def main(args: Array[String]): Unit = {
    val properties = new Properties()
    properties.load(new FileInputStream("src\\main\\scala\\dli_and_obs\\dli.properties"))

    //C:\Users\o2o-rd-0005\IdeaProjects\o2odata_commend\src\main\scala\dli_and_obs\dli.properties

    val cluster_name = "o2o16u" // o2o16u/data 常用
    val running_num = get_num(cluster_name,properties,"RUNNING")
    val waiting_num = get_num(cluster_name,properties,"STARTING")

    println(cluster_name + " 正在运行任务数： "+ running_num.size)
    running_num.map(_.getName).foreach(x=>println("\t正在运行任务名称：" + x))
    println(cluster_name + " 等待运行任务数： "+ waiting_num.size)

  }

  def get_num(cluster_name:String,properties: Properties,state:String)={
    val cli_client = utils.dli_utils.get_dli_client(properties)
    import scala.collection.JavaConverters._

    var batchJobs = cli_client.listAllBatchJobs(cluster_name,0,30).asScala
      .filter(_.getState.toString.equals(state))

    batchJobs
  }


}
